package com.example.demo.test;

import com.example.demo.component.osql.bean.osql_consts;
import com.example.demo.component.osql.bean.osql_param;
import com.example.demo.component.osql.osql_client;

import java.lang.reflect.Field;

/**
 * @ClassName osql
 * @Description
 * @date 2022/11/17 15:22
 * @Author yanceysong
 * @Version 1.0
 */
public class osql_test {

    public static void main(String[] args) {
        osql_param osql_param = new osql_param();
        osql_param.setSql_path("sdadasdas");
        Field[] fields = osql_param.getClass().getDeclaredFields();

        for (Field field : fields) {
            try {
                field.setAccessible(true);
                System.out.println(field.getName()+" : "+field.get(osql_param));
                //判断是是空字符串
                if (field.get(osql_param) == null || field.get(osql_param).equals("")) {

                }
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                field.setAccessible(false);
            }
        }


        osql_param.setPassword("Oraps123");
        osql_param.setServer_ip("172.21.1.20");
        osql_param.setUsername("sa");
        osql_client client = new osql_client();
//        //先备份数据库
        osql_param.setDatabase("yanceysong1");
        osql_param.setBak_path("D:\\test5.bak");
        String result_backup = client.execute(osql_param, osql_consts.BACKUP);
        System.out.println(result_backup);
//        //再还原数据库
        osql_param.setDatabase("songyang1");
        osql_param.setRestore_path("D:\\a\\");
        osql_param.setBak_path("D:\\test.bak");
        String result_restore = client.execute(osql_param, osql_consts.RESTORE);
        System.out.println(result_restore);
        //尝试执行SQL
        osql_param.setDatabase("songyang");
        osql_param.setSql_path("C:\\Users\\BG264\\Desktop\\user_table.sql");
        String result_sql = client.execute(osql_param, osql_consts.EXEC_SQL);
        System.out.println(result_sql);
    }
}
